% DO THIS BEFORE EXECUTING
% addpath(genpath('/media/sda2/Users/Nermine/Desktop/code/mpt'));

clc;
clear;
N = 6;
M = 10000;

X = intvar(N,N,'full');

C = [M 12  M  M  9 16;
    12  M 19 12  M 15;
     M 19  M 21  M 17; 
     M 12 21  M 10 16;
     9  M  M 10  M 10;
    16 15 17 16 10  M];

Y = binvar(N,N,'full');

R = (N-1)*ones(N,N);
for i=1:6
    for j=1:6
        if(j==1)
            R(i,j) = 1;
        end
        if(i==1)
            R(i,j) = N;
        end
    end
end


C1 = [sum(Y(:,1)) sum(Y(:,2)) sum(Y(:,3)) sum(Y(:,4)) sum(Y(:,5)) sum(Y(:,6))]' ; % N hardcoded here.
C2 = [sum(Y(1,:)) sum(Y(2,:)) sum(Y(3,:)) sum(Y(4,:)) sum(Y(5,:)) sum(Y(6,:))]' ; % N hardcoded here.

for k=1:6
    C3(k) = sum(X(:,k))-sum(X(k,:)) -1;
    if(k==1)
        C3(k) = C3(k) +N;
    end
    
    X(k,k) = 0;
    Y(k,k) = 0;
    
end


F = [C1==ones(N,1), C2==ones(N,1), sum(X(:,6))==1, C3==0, X>=0, X<=R.*Y];

solvesdp(F,sum(sum(C.*X)),sdpsettings('solver','bnb'));

Xsol = double(X)